﻿using Maltose.Configuration;

namespace Maltose.MessageQueue
{
    /// <summary>
    /// 消息队主机列配置
    /// </summary>
    public class MessageQueueHostConfig
    {
        /// <summary>
        /// 主机地址
        /// </summary>
        public string HostName { get; set; }

        /// <summary>
        /// 主机端口
        /// </summary>
        public int Port { get; set; }

        /// <summary>
        /// 用户账号
        /// </summary>
        public string UserName { get; set; }

        /// <summary>
        /// 用户密码
        /// </summary>
        public string Password { get; set; }

        /// <summary>
        /// 消息队主机列配置
        /// </summary>
        public MessageQueueHostConfig()
        {
            HostName = UseConfigFactory.Json.Get<string>("MQConnectionString:Host");

            if (string.IsNullOrWhiteSpace(HostName))
            {
                throw new System.Exception("初始化MQ配置错误，如果使用默认读取信息,请保证 appsettings.json 配置文件下 MQConnectionString:Host 存在");
            }

            Port = UseConfigFactory.Json.Get<int>("MQConnectionString:Port");
            if (Port <= 0)
            {
                throw new System.Exception("初始化MQ配置错误，如果使用默认读取信息,请保证 appsettings.json 配置文件下 MQConnectionString:Port 存在");
            }
            UserName = UseConfigFactory.Json.Get<string>("MQConnectionString:UserName");
            if (string.IsNullOrWhiteSpace(UserName))
            {
                throw new System.Exception("初始化MQ配置错误，如果使用默认读取信息,请保证 appsettings.json 配置文件下 MQConnectionString:UserName 存在");
            }
            Password = UseConfigFactory.Json.Get<string>("MQConnectionString:Password");
            if (string.IsNullOrWhiteSpace(Password))
            {
                throw new System.Exception("初始化MQ配置错误，如果使用默认读取信息,请保证 appsettings.json 配置文件下 MQConnectionString:Password 存在");
            }
        }
    }
}
